package com.ytjj.qmyx.admin.controller;

import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.OperLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.model.request.LiveRequest;
import com.ytjj.qmyx.admin.service.LiveService;
import com.ytjj.qmyx.mall.model.Live;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/live")
public class LiveController {

    @Autowired
    private LiveService liveService;

    @PostMapping("/list")
    @OperLog(operModule = "直播管理模块", operDesc = "直播列表", operType = SysLogConstants.OPERATION_SELECT)
    public CommonResult getLiveList(@RequestBody LiveRequest liveRequest){
        CommonPage<Live> page = liveService.getLiveList(liveRequest);
        return CommonResult.success(page);
    }

    @PostMapping("/insertLive")
    @OperLog(operModule = "直播管理模块", operDesc = "增加直播房间", operType = SysLogConstants.OPERATION_ADD)
    public CommonResult insertLive(@RequestBody LiveRequest liveRequest){
        int count = liveService.insertLive(liveRequest);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @PostMapping("/updateLive")
    @OperLog(operModule = "直播管理模块", operDesc = "修改直播房间", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult updateLive(@RequestBody LiveRequest liveRequest){
        int count = liveService.updateLive(liveRequest);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @PostMapping("/isRecommend")
    @OperLog(operModule = "直播管理模块", operDesc = "修改直播间推荐/不推荐状态", operType = SysLogConstants.OPERATION_UPDATE)
    public CommonResult isRecommend(@RequestBody LiveRequest liveRequest){
        int count = liveService.isRecommend(liveRequest.getId(), liveRequest.getIsRecommend());
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

}
